/*
 * Copyright (C) 2017 zhouyou(478319399@qq.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.shuyihui.rxhttp.model

/**
 *
 * 描述：提供的默认的标注返回api
 */
class ApiResult<T> {
    private var code: String? = null
    var msg: String? = null
    private var subCode: String? = null
    private var subMsg: String? = null
    var data: T? = null
        private set

    fun getCode(): Int {
        return code!!.toInt()
    }

    fun setCode(code: Int) {
        this.code = code.toString()
    }

    fun setData(data: T) {
        this.data = data
    }

    val isOk: Boolean
        get() = "000" == code || "0" == code

    override fun toString(): String {
        return "ApiResult{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", subCode='" + subCode + '\'' +
                ", subMsg='" + subMsg + '\'' +
                ", data=" + data +
                '}'
    }

    fun getSubCode(): String {
        return if (subCode == null) "" else subCode!!
    }

    fun setSubCode(subCode: String?) {
        this.subCode = subCode
    }

    fun getSubMsg(): String {
        return if (subMsg == null) "" else subMsg!!
    }

    fun setSubMsg(subMsg: String?) {
        this.subMsg = subMsg
    }
}